<?php

declare(strict_types=1);

namespace app\model\admin;

use think\facade\Db;
use think\Model;


/**
 * 用户反馈表 数据模型类
 */
class EsxdmSysFeedbackModel extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'esxdm_sys_feedback';

    // 自动时间戳
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'created_at';
    protected $updateTime = 'updated_at';


    /**
     * is_read 字段内容
     */
    protected $isReadData = ['否',    '是'];

    /**
     * 返回 is_read 字段内容
     */
    public function getIsReadData()
    {
        return $this->isReadData;
    }

    /**
     * 返回 is_read 字段获取器的值
     */
    public function getIsReadTextAttr($value)
    {
        $value = intval($this->is_read);
        return isset($this->isReadData[$value]) ? $this->isReadData[$value] : $value;
    }

    /**
     * status 字段内容
     */
    protected $statusData = ['隐藏',    '正常'];

    /**
     * 返回 status 字段内容
     */
    public function getStatusData()
    {
        return $this->statusData;
    }

    /**
     * 返回 status 字段获取器的值
     */
    public function getStatusTextAttr($value)
    {
        $value = intval($this->status);
        return isset($this->statusData[$value]) ? $this->statusData[$value] : $value;
    }

    public static function getUsers($pageSize = 10)
    {
        $list = Db::table('esxdm_sys_feedback')->field('user_id')->group('user_id')->paginate($pageSize)->toArray();
        if (!$list) {
            return [];
        }
        $userIds = [];
        $list = $list['data'];
        foreach ($list as $row) {
            $userIds[] = $row['user_id'];
        }
        return Db::table('usr_user')->where('id', 'in', $userIds)->field('id, user_name')->select();
    }
}
